package com.wangwei.sort;

import edu.princeton.cs.algs4.StdOut;

public abstract class Example {
    //比较
    protected boolean less(Comparable v,Comparable w){
        return v.compareTo(w) < 0;
    }

    //交换
    protected void exch(Comparable[] arr,int i ,int j){
        Comparable temp = arr[i];
        arr[i]= arr[j];
        arr[j]= temp;
    }

    //展示
    protected  void show(Comparable[] arr){
        for(int i =0 ;i < arr.length; i++){
            StdOut.println(arr[i]);
        }
        StdOut.println();
    }

    //校验
    protected  boolean isSorted(Comparable[] arr){
        for(int i=0;i <arr.length;i++){
            if(less(arr[i],arr[i-1])) return false;
        }
        return true;
    }



    public abstract void sort(Comparable[] arr);
}
